package tijdserver;

import java.util.HashMap;
import util.Message;
import util.NetwerkComponent;
import util.Sniffer;

/**
 *
 * @author Jonas
 */
public class TijdServerDummy implements TijdServer {
    private static int IDCounter=0;
    private String ID;
    private Sniffer sniffy;

    public TijdServerDummy() {
        ID = "TS-id"+IDCounter;
        IDCounter++;
    }

    public void sendMessage(Message msg, NetwerkComponent sender) {
        if(sniffy != null)
            sniffy.readTransmission(msg,sender,this);

        HashMap<String,Object> fields = new HashMap<String,Object>();
        fields.put("data", "ok from "+ID);
        sender.sendMessage(new Message(Message.MessageType.TS_ANSWER,fields), this);
    }

    @Override
    public String toString() {
        return ID;
    }

    public void addSniffer(Sniffer sniffer) {
        sniffy = sniffer;
        System.out.println("Sniffer added");
    }

    public void removeSniffer() {
        sniffy = null;
        System.out.println("Sniffer removed");
    }
}
